class Solution(object):
    def fullJustify(self, words, maxWidth):
        """
        :type words: List[str]
        :type maxWidth: int
        :rtype: List[str]
        """
        return_list = []
        now_num = 0
        now_bear = 0
        now_list = []
        for word in words:
            if now_num + len(word) + now_bear <= maxWidth:
                now_list.append(word)
                now_num += len(word)
                now_bear += 1
            else:
                word_count = len(now_list)
                left_length = maxWidth - now_num
                if word_count >= 2:
                    avg_bear = left_length // (word_count - 1)
                    left_bear = left_length % (word_count - 1)
                else:
                    avg_bear = left_length
                    left_bear = 0
                s = ''
                for w in now_list[:-1]:
                    s += w
                    s += avg_bear * ' '
                    if left_bear > 0:
                        s += ' '
                        left_bear -= 1
                s += now_list[-1]
                if word_count == 1:
                    s += avg_bear * ' '
                return_list.append(s)
                now_list = [word]
                now_num = len(word)
                now_bear = 1
        left_length = maxWidth - now_num - (now_bear - 1)
        s = ''
        for w in now_list[:-1]:
            s += w
            s += ' '
        s += now_list[-1]
        s += left_length * ' '
        return_list.append(s)
        return return_list


data = Solution()
words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"]
maxWidth = 20
print(data.fullJustify(words, maxWidth))